//
//  ImageWaterView.h
//  LoveTrail
//
//  Created by giantumbrella on 15/6/24.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "SelfImageVIew.h"
#import "ProductInfoModel.h"

@implementation SelfImageVIew

-(id)initWithImageInfo:(ImageInfo*)imageInfo y:(float)y  withA:(int)a
{
    
    float imageW = imageInfo.width;
    float imageH = imageInfo.height;
    //缩略图宽度和宽度
    float width = WIDTH*1.5;
    float height = width * imageH / imageW;

    self = [super initWithFrame:CGRectMake(0, y, WIDTH, height + SPACE)];
    if (self) {
        self.data = imageInfo;
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(SPACE / 2 , SPACE / 2 , width, height)];
        [self addSubview:bgView];
    
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(SPACE / 2 , SPACE / 2 , width, height*0.7)];
        NSURL *url = [NSURL URLWithString:imageInfo.thumbURL];
        [imageView setImageWithURL:url placeholderImage:nil];
        imageView.backgroundColor = [UIColor greenColor];
        [bgView addSubview:imageView];
        if (a==0) {
#warning 在此处设置第一个不同
        }
        else
        {
            //如果想加别的信息在此可加
            UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake(0, imageView.frame.size.height+imageView.frame.origin.y, imageView.frame.size.width, 20)];
            titleLable.text = @"韩国进口海地村鳕鱼肠宝宝香肠鱼肉肠婴儿食品儿童零食婴儿鱼肠";
//            titleLable.text = self.productInfoModel.productTitle;
            titleLable.font = [UIFont systemFontOfSize:10];
            titleLable.numberOfLines = 0;
            [titleLable sizeToFit];
            [bgView addSubview:titleLable];
            
            UILabel *nowPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(3, titleLable.frame.size.height+titleLable.frame.origin.y, bgView.frame.size.width*0.2, bgView.frame.size.height*0.2)];
            nowPriceLabel.text = @"￥29";
//            nowPriceLabel.text = self.productInfoModel.currentPrice;
            nowPriceLabel.font = [UIFont systemFontOfSize:12];
            [bgView addSubview:nowPriceLabel];
            
            UILabel *oldPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(nowPriceLabel.frame.origin.x+nowPriceLabel.frame.size.width+10, titleLable.frame.size.height+titleLable.frame.origin.y, bgView.frame.size.width*0.2, bgView.frame.size.height*0.2)];
            oldPriceLabel.text = @"￥29";
//            oldPriceLabel.text = self.productInfoModel.originalPrice;
            oldPriceLabel.font = [UIFont systemFontOfSize:12];
            [bgView addSubview:oldPriceLabel];
            
            UILabel *haveBuyLabel = [[UILabel alloc] initWithFrame:CGRectMake(oldPriceLabel.frame.origin.x+oldPriceLabel.frame.size.width, titleLable.frame.size.height+titleLable.frame.origin.y, bgView.frame.size.width*0.6, bgView.frame.size.height*0.2)];
            haveBuyLabel.text = @"已购买数：396";
//            haveBuyLabel.text = self.productInfoModel.currentPrice;
            haveBuyLabel.font = [UIFont systemFontOfSize:12];
            [bgView addSubview:haveBuyLabel];
        }
       
    }
    return self;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.delegate clickImage:self.data];
}
@end
